(Music)
Hello and welcome. In this video,
we'll go over date and time SQL functions built into
the database. So let's get started.
Most databases contain special data types
for dates and times.
Db2 contains date, time, and timestamp types.
In Db2, date has eight digits:
for year, month, and day.
Time has six digits:
hours, minutes, and seconds.
Timestamp has 20 digits: year,
month, day, hour, minute, seconds,
and microseconds where double X represents month
and six Zs or Zs represents microseconds.
Functions exist to extract the day,
month, day of month,
day of week, day of year,
week, hour, minute, and second.
Let us look at some examples of
queries for date and time functions.
The day function can be used to
extract the day portion from a date.
For example, to get the day portion
for each rescue date involving cat,
select
DAY (RESCUEDATE) from PETRESCUE where ANIMAL equals cat.
Date and time functions can be used in the where clause.
For example, to get the number
of rescues during the month of May,
that is, from Month 5,
select COUNT star from PETRESCUE
where MONTH (RESCUEDATE) equals 05.
You can also perform date or time arithmetic.
For example, to find out what
date it is three days
after each rescue date,
maybe you
want to know this
because the rescue needs to be
processed within three days.
select (RESCUEDATE plus three DAYS) from PETRESCUE.
Special registers current time
and current date are also available.
For example, to find how many days
have passed since each rescue date till now-
(CURRENT_DATE minus RESCUEDATE) from PETRESCUE.
The result will be in years, months, days.
In this video, we looked at different types of
built in SQL functions for working
with dates and times.
Thanks for watching.
(Music)